cmake_minimum_required(VERSION 3.0.0)
project(nbi VERSION 0.1.0)
exec_program(gcc ARGS "-v 2>&1 | sed -n '/gcc version/p' | awk -F ' ' '{print $3}'" OUTPUT_VARIABLE CMD_OUT RETURN_VALUE CMD_RET)
if($(CMD_RET))
    message(FATAL_ERROR "${CMAKE_C_COMPILER} not found.")
else()
    set(GCC_VERSION ${CMD_OUT})
endif()

if(${GCC_VERSION} STRLESS "5.0.0")
    message(FATAL_ERROR "gcc version must great 5.0.0 to support c++14.")
endif()
if(NOT EXISTS $ENV{NB_ENV_TOP})
    message(FATAL_ERROR "please cd to ivse top and run \"source build/env_setup.sh\" first.")
endif()

exec_program(git  ARGS  "log --pretty=format:%h --max-count=1 | awk '{print $1}'" OUTPUT_VARIABLE CMD_OUT RETURN_VALUE CMD_RET)
string(TIMESTAMP BUILD_TIME "%Y%m%d-%H%M")
set(BUILD_INFO "${BUILD_TIME}")
add_definitions(-D__BUILD_INFO__=${BUILD_INFO})
add_definitions(-D__GIT_VER__=${CMD_OUT})
message(STATUS "BUILD_INFO: " ${BUILD_INFO})
message(STATUS "GIT_VER: " ${CMD_OUT})

exec_program(protoc ARGS "--version 2>&1 | sed -n '/libprotoc/p' | awk -F ' ' '{print $2}'" OUTPUT_VARIABLE PROTO_VERSION RETURN_VALUE CMD_RETURN)
if(${PROTO_VERSION} VERSION_LESS "3.6.0")
    message(FATAL_ERROR "protoc version must great 3.6.0.")
endif()

set(THIRD_PARTY_LIB_PATH $ENV{NB_ENV_THIRD_PARTY_PREBUILT_DIR})

# complier options
add_definitions(-DPLATFORM_POSIX)
add_definitions(-DUSE_EIGEN_FOR_BLAS)
add_definitions(-DDEBUGFATFLOW)
add_definitions(-DONNX_ML=1)
add_definitions(-DONNX_NAMESPACE=onnx)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g -fPIC -O3 -std=c++14 -lpthread -fopenmp -lrt -ldl -pthread")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -g -fPIC -O3 -fopenmp -std=c99")


include_directories(
    ${PROJECT_SOURCE_DIR}
    ${THIRD_PARTY_LIB_PATH}/protobuf/x86_64/${GCC_VERSION}/include/
    ${THIRD_PARTY_LIB_PATH}/eigen/
)

link_directories(
    ${THIRD_PARTY_LIB_PATH}/protobuf/x86_64/${GCC_VERSION}/lib
)

# add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/third_party/onnx)
include(${CMAKE_CURRENT_LIST_DIR}/fastflow/CMakeLists.txt)
include(${CMAKE_CURRENT_LIST_DIR}/onnx/CMakeLists.txt)
file(GLOB_RECURSE MAIN_SRC sample/*.cc)

add_executable(nbi ${MAIN_SRC} ${MONOLITH_INFERENCE_OBJECTS})

set(LINK_LIB
    libprotobuf.a
    libprotobuf-lite.a)

target_link_libraries(nbi ${LINK_LIB})
